package org.zjz.fun

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, ScalaObjectMapper}
import org.zjz.fun.BattBean.objectMapper
import org.zjz.fun.BattIteratorAnalysis.SimplePackage

import scala.collection.mutable.ListBuffer

object BattIteratorAnalysis {
  var ssim: SimplePackage = _
  val objectMapper = new ObjectMapper() with ScalaObjectMapper
  objectMapper.registerModule(DefaultScalaModule)

  case class SimplePackage(title: String, wordP: String, child: ListBuffer[SimplePackage])

  def analysis(list: ListBuffer[SimplePackage], batt: BattBean): ListBuffer[SimplePackage] = {
    var myList = new ListBuffer[SimplePackage]()
    mYanalysis(null, batt)
    myList
  }

   def mYanalysis(sim: SimplePackage, batt: BattBean): SimplePackage = this.synchronized {
    var _sim = sim
     if (sim==null) {
       _sim=SimplePackage(batt.title, batt.titleType, new ListBuffer[SimplePackage]())
     }
     var simIndex = SimplePackage(batt.title, batt.titleType, new ListBuffer[SimplePackage]())
     _sim.child append simIndex
     while (batt.hasNext) {
      mYanalysis(simIndex, batt.next())
    }
     simIndex
  }
}
